package com.example.mapper;

import com.example.bean.Equipment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EquipmentMapper {

    //器材分页查询
    @Select("select * from equipment ")
    List<Equipment> queryEquipment();

    //根据id查询 器材
    @Select("select * from equipment where equipmentId = #{equipmentId}")
    Equipment selectById(@Param("equipmentId") int equipmentId);

    //根据用户id器材查询
    @Select("select * from equipment where userId = #{userId}")
    List<Equipment> selectByUserId(@Param("userId") int userId);

    //根据名称器材查询
    @Select("select * from equipment where equipmentName like #{equipmentName}")
    List<Equipment> selectByName(@Param("equipmentName") String equipmentName);

    //查询维修器材
    @Select("select * from equipment where equipmentState = #{equipmentState}")
    List<Equipment> selectByState(@Param("equipmentState") int equipmentState);

    //器材购置新增
    @Insert("insert into equipment(equipmentName, equipmentState, equipmentCharges) values(#{equipmentName}, #{equipmentState}, #{equipmentCharges})")
    void addEquipment(Equipment equipment);

    //器材报废删除
    @Delete("delete from equipment where equipmentId = #{equipmentId}")
    void deleteEquipment(@Param("equipmentId") int equipmentId);

//    //器材维护报修
//    @Update("update equipment set equipmentState = 2, userId = #{userId} where equipmentId = #{equipmentId}")
//    int repairEquipment(@Param("equipmentId") int equipmentId, @Param("userId") int userId);
//
//    //器材租用
//    @Update("update equipment set equipmentState = 1, userId = #{userId} where equipmentId = #{equipmentId}")
//    int rentEquipment(@Param("equipmentId") int equipmentId, @Param("userId") int userId);

    //器材回收或维修完成
    @Update("update equipment set equipmentState = #{equipmentState}, userId = #{userId} where equipmentId = #{equipmentId}")
    int updateEquipment(@Param("equipmentState") int equipmentState, @Param("equipmentId") int equipmentId, @Param("userId") int userId);

    //器材租用收费标准查询
    @Select("select equipmentCharges,equipmentName from equipment where equipmentId = #{equipmentId}")
    List<Equipment> chargeEquipment(@Param("equipmentId") int equipmentId);

    @Select("select * from equipment order by startTime desc limit 10")
    List<Equipment> selectTime();

}
